package com.hoku.auth.service.security;

import com.hoku.auth.dao.IUserDao;
import com.hoku.auth.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * OAuth2用户验证服务，验证用户合法性
 * @author ZHUFEIFEI
 */
@Slf4j
@Service
public class BaseUserDetailService implements UserDetailsService{

    @Autowired
    private IUserDao dao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = this.dao.findByUsername(username);
        //user != null 则验证通过
        return user;
    }

}
